<template>
    <div>
        <Row>
            <Col span="16">
                <ButtonGroup >
                    <Button  type="primary"  @click="modal1 = true">添加</Button>
                    <Button  type="error" @click="selremove">多个删除</Button>
                </ButtonGroup>
            </Col>
            <Col span="8">
                <!-- <Input v-model="filter.name" >
                    <Button slot="append" icon="ios-search" @click="search"></Button>
                </Input> -->
                <Input v-model="filter.name">
                    <Select v-model="showsel" slot="prepend" style="width: 80px">
                        <Option value="name">name</Option>
                        <Option value="city">city</Option>
                        <Option value="gender">gender</Option>
                    </Select>
                    <Button slot="append" icon="ios-search" @click="search"></Button>
                </Input>
            </Col>
        </Row><br/>
        <Table border :columns="columns" :data="list" @on-selection-change="onSelect"></Table>
        <Page :total="filter.total" show-sizer :page-size="filter.limit" :page-size-opts="[5, 10, 20, 30, 40]" @on-change="onPageChange" @on-page-size-change="onPageSizeChange"></Page>

        <Modal
        v-model="modal1"
        title="数据操作"
        @on-ok="ok"
        @on-cancel="cancel">

    <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
        <FormItem label="Name" prop="name">
            <Input v-model="formValidate.name" placeholder="Enter your name"></Input>
        </FormItem>
        <FormItem label="Password" prop="password">
            <Input v-model="formValidate.password" placeholder="Enter your password" type="password"></Input>
        </FormItem>
        <FormItem label="Mail" prop="mail">
            <Input v-model="formValidate.mail" placeholder="Enter your e-mail"></Input>
        </FormItem>
        <FormItem label="City" prop="city">
            <Select v-model="formValidate.city" placeholder="Select your city">
                <Option value="浙江">浙江</Option>
                <Option value="北京">北京</Option>
                <Option value="上海">上海</Option>
                <Option value="深圳">深圳</Option>
            </Select>
        </FormItem>
        <FormItem label="Height" prop="height">
            <Input v-model="formValidate.height" placeholder="Enter your height"></Input>
        </FormItem>
        <FormItem label="Gender" prop="gender">
            <RadioGroup v-model="formValidate.gender">
                <Radio label="男">男</Radio>
                <Radio label="女">女</Radio>
            </RadioGroup>
        </FormItem>
        <FormItem label="Xingzuo" prop="xingzuo" >
            <Input v-model="formValidate.xingzuo" placeholder="Enter your xingzuo" ></Input>
        </FormItem>
        <FormItem label="Weight" prop="weight">
            <Input v-model="formValidate.weight" placeholder="Enter your weight"></Input>
        </FormItem>
        <FormItem label="Job" prop="job">
            <Input v-model="formValidate.job" placeholder="Enter your job"></Input>
        </FormItem>
        <FormItem label="Age" prop="age">
            <Input v-model="formValidate.age" placeholder="Enter your age"></Input>
        </FormItem>
        <FormItem>
            <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
            <Button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">清空</Button>
        </FormItem>
    </Form>



    </Modal>
    </div>
</template>


<script>
import Base from "../../common/Base";
export default {
  mixins: [Base],
  data() {
    return {
      searchdata: "filter.name",
      showsel: "name",
      selectdata: [],
      formValidate: {
        name: "",
        password: "",
        mail: "",
        city: "",
        height: "",
        gender: "",
        xingzuo: "",
        weight: "",
        job: "",
        age: ""
      },
      ruleValidate: {
        name: [{ required: true, message: "用户名不能为空", trigger: "blur" }],
        password: [{ required: true, message: "密码不能为空", trigger: "blur" }],
        mail: [
          { required: true, message: "邮箱不能为空", trigger: "blur" },
          { type: "email", message: "请输入正确的邮箱", trigger: "blur" }
        ],
        city: [{ required: true, message: "请选择城市", trigger: "change" }],
        height: [{ required: true, message: "身高不能为空", trigger: "blur" }],
        gender: [{ required: true, message: "请选择性别", trigger: "change" }],
        xingzuo: [{ required: true, message: "星座不能为空", trigger: "blur" }],
        weight: [{ required: true, message: "体重不能为空", trigger: "blur" }],
        job: [{ required: true, message: "工作不能为空", trigger: "blur" }],
        age: [{ required: true, message: "年龄不能为空", trigger: "blur" }]
      },

      columns: [
        {
          type: "selection",
          width: 60,
          align: "center"
        },
        {
          title: "用户名称",
          key: "name",
          render: (h, params) => {
            return h("div", [
              h("Icon", {
                props: {
                  type: "person"
                }
              }),
              h("strong", params.row.name)
            ]);
          }
        },
        {
          title: "邮箱",
          key: "mail"
        },
        {
          title: "城市",
          key: "city"
        },
        {
          title: "身高",
          key: "height"
        },
        {
          title: "性别",
          key: "gender"
        },
        {
          title: "星座",
          key: "xingzuo"
        },
        {
          title: "体重",
          key: "weight"
        },
        {
          title: "工作",
          key: "job"
        },
        {
          title: "年龄",
          key: "age"
        },
        {
          title: "操作",
          key: "action",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.show(params.row);
                    }
                  }
                },
                "修改"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.remove(params);
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ]
    };
  }
};
</script>